package business_opportunity

import (
	"context"
	pb "git.mycaigou.com/gfyx/micro-gfyx-oppty-service/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/business_opportunity"
	"git.mycaigou.com/gfyx/micro-gfyx-oppty-service/service/business_opportunity/order"
)

type orderServer struct {
	orderService order.OrderServiceIface
}

func NewOrderServer(
	orderService order.OrderServiceIface,
) pb.OrderServiceServer {
	return &orderServer{
		orderService: orderService,
	}
}

func (s *orderServer) GetOrderList(ctx context.Context, request *pb.GetOrderListRequest) (*pb.GetOrderListResponse, error) {
	resp, err := s.orderService.QueryOrderList(ctx, request)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *orderServer) GetOrderDetail(ctx context.Context, request *pb.GetOrderDetailRequest) (*pb.GetOrderDetailResponse, error) {
	resp, err := s.orderService.OrderDetail(ctx, request)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *orderServer) SaveOrder(ctx context.Context, request *pb.SaveOrderRequest) (*pb.SaveOrderResponse, error) {
	id, isPaid, err := s.orderService.SaveOrder(ctx, request)
	if err != nil {
		return nil, err
	}
	return &pb.SaveOrderResponse{
		Id:     id,
		IsPaid: isPaid,
	}, nil
}

func (s *orderServer) PreviewOrder(ctx context.Context, request *pb.PreviewOrderRequest) (*pb.PreviewOrderResponse, error) {
	resp, err := s.orderService.PreviewOrder(ctx, request)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
